package com.kang.controller;

import com.github.pagehelper.PageInfo;
import com.kang.bean.bot.WarMap;
import com.kang.commons.Result;
import com.kang.dto.QueryDto;
import com.kang.dto.WarMapDto;
import com.kang.service.warMap.WarMapService;
import com.kang.vo.WarMapVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: service
 * @description: 地图
 * @author: K.faWu
 * @create: 2022-05-09 17:52
 **/
@Slf4j
@RestController
@RequestMapping("warMap")
public class WarMapController {
    private final WarMapService warMapService;

    public WarMapController(WarMapService warMapService) {
        this.warMapService = warMapService;
    }

    @PostMapping("getByCodeAndGroup")
    public Result<?> getByCodeAndGroup(@RequestBody WarMapDto warMapDto) {
        WarMapDto warMapDto1 = warMapService.getByCodeAndGroup(warMapDto);
        return Result.success(warMapDto1);
    }

    /**
     * 获取地图列表
     */
    @PostMapping("getList")
    public Result<?> getList(@RequestBody List<QueryDto> queryDtos, Pageable page) {
        PageInfo<WarMap> pageInfo = warMapService.getList(queryDtos, page);
        return Result.success(pageInfo);
    }

    /**
     * 保存地图
     */
    @PostMapping("add")
    public Result<?> add(@RequestBody WarMapDto warMapDto) {
        warMapService.add(warMapDto);
        return Result.success();
    }


    /**
     * 随机生成地图
     */
    @PostMapping("create")
    public Result<?> create(@RequestBody WarMapDto warMapDto) {
        List<WarMapVo> list = warMapService.create(warMapDto);
        return Result.success(list);
    }
}
